$(document).ready(function (){
    $(".login").click(function (){
        login();
        return false;
    });

    $(".zhuce").click(function (){
        zhuce();
        return false;
    });
});

function zhuce(){
    window.location.href = "/toZhuce";
}

/**
 * 登录函数
 */
function login() {
    var username = $("input[name='username']").val();
    var password = $("input[name='password']").val();

    $.ajax({
        url: "/login/userLogin",
        type: 'POST',
        data: {
            "username": username,
            "password": password
        },
        dataType: "JSON",
        async: false,
        success: function (res) {

            if(res.code === "200") {
                window.location.href = "/toIndex";
            }else {
                alert(res.msg)
            }
        },
        error: function (e){
            alert('发生错误')
        }

    })

}

function toIndex(){
    window.location.href = "/toIndex";
}
